from rest_framework import serializers

from goods.models import SPU, SpecificationOption, SPUSpecification, SKU, GoodsCategory
from meiduo_admin.serializers.skus import SKUSpecSerializer


class SPUSimpleSerializer(serializers.ModelSerializer):
    '''SPU序列化器类'''
    class Meta:
        model=SPU
        fields=('id','name')

class SpecOptionSerializer(serializers.ModelSerializer):
    #SPU规格序列化器类
    class Meta:
        model=SpecificationOption
        fields=('id','value')

class SPUSpecSerializer(serializers.ModelSerializer):
    '''SPU序列化器类'''
    #关联对象的嵌套序列化
    spu=serializers.StringRelatedField(label='SPU名称')
    spu_id=serializers.IntegerField(label='SPU ID')

    #关联对象的嵌套序列化
    options=SpecOptionSerializer(label='Opt选项',many=True)
    class Meta:
        model=SPUSpecification
        fields=('id','name','spu','spu_id','options')


